home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / LSSETBUF.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  94 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lssetbuf.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10.  
  11. /* library headers */
  12. #include <blkio.h>
  13.  
  14. /* local headers */
  15. #include "lseq_.h"
  16.  
  17. /*man---------------------------------------------------------------------------
  18. NAME
  19.      lssetbuf - assign buffering to an lseq
  20.  
  21. SYNOPSIS
  22.      #include <lseq.h>
  23.  
  24.      int lssetbuf(lsp, buf)
  25.      lseq_t *lsp;
  26.      void *buf;
  27.  
  28. DESCRIPTION
  29.      The lssetbuf function causes the storage area pointed to by buf
  30.      to be used by the lseq associated with lseq pointer lsp instead
  31.      of an automatically allocated buffer area.  If buf is the NULL
  32.      pointer, lsp will be completely unbuffered.
  33.  
  34.      The size of the storage area needed can be obtained using the
  35.      LSBUFSIZE() macro:
  36.  
  37.           char buf[LSBUFSIZE(RECSIZE, LSBUFCNT)];
  38.           lssetbuf(lsp, (void *)buf);
  39.  
  40.      where RECSIZE is the size of the records in the lseq and LSBUFCNT
  41.      is the default number of records buffered when an lseq is opened.
  42.      LSBUFCNT is defined in <lseq.h>.  If the number of records
  43.      buffered has been changed using lssetvbuf, then that number
  44.      should be used in place of LSBUFCNT.
  45.  
  46.      lssetbuf may be called at any time after opening the lseq,
  47.      before and after it is read or written; the buffers are flushed
  48.      before installing the new buffer area.
  49.  
  50.      lssetbuf will fail if one or more of the following is true:
  51.  
  52.      [EINVAL]       lsp is not a valid lseq pointer.
  53.      [LSENBUF]      buf is not the NULL pointer and lsp
  54.                     is not buffered.
  55.      [LSENOPEN]     lsp is not open.
  56.  
  57. SEE ALSO
  58.      lssetvbuf, lssync.
  59.  
  60. DIAGNOSTICS
  61.      Upon successful completion, a value of 0 is returned.  Otherwise,
  62.      a value of -1 is returned, and errno set to indicate the error.
  63.  
  64. ------------------------------------------------------------------------------*/
  65. #ifdef AC_PROTO
  66. int lssetbuf(lseq_t *lsp, void *buf)
  67. #else
  68. int lssetbuf(lsp, buf)
  69. lseq_t *lsp;
  70. void *buf;
  71. #endif
  72. {
  73.     /* validate arguments */
  74.     if (!ls_valid(lsp)) {
  75.         errno = EINVAL;
  76.         return -1;
  77.     }
  78.  
  79.     /* check if not open */
  80.     if (!(lsp->flags & LSOPEN)) {
  81.         errno = LSENOPEN;
  82.         return -1;
  83.     }
  84.  
  85.     /* assign buffering */
  86.     if (bsetbuf(lsp->bp, buf) == -1) {
  87.         if (errno == BENBUF) errno = LSENBUF;
  88.         LSEPRINT;
  89.         return -1;
  90.     }
  91.  
  92.     return 0;
  93. }
  94.